package com.liliudong.template.api.admin.controller.generate;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.liliudong.template.biz.service.generate.GenerateProjectService;
import com.liliudong.template.common.R;
import com.liliudong.template.common.dto.generate.GenerateProjectAddDTO;
import com.liliudong.template.common.dto.generate.GenerateProjectModifyDTO;
import com.liliudong.template.common.dto.generate.GenerateProjectPageDTO;
import com.liliudong.template.common.vo.PageVO;
import com.liliudong.template.common.vo.generate.GenerateProjectDetailVO;
import com.liliudong.template.common.vo.generate.GenerateProjectPageVO;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 代码生成-项目配置表
 *
 * @author ldli5
 * @date 2024-07-03 12:33:21
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/generate/dept")
public class GenerateProjectController {

	private final GenerateProjectService generateProjectService;

	/**
	 * 添加
	 *
	 * @param generateProjectAddDTO 新增dto
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("generate:project:add")
	@PostMapping
	public R<?> addOne(@RequestBody @Validated GenerateProjectAddDTO generateProjectAddDTO) {
		generateProjectService.addOne(generateProjectAddDTO);
		return R.ok();
	}

	/**
	 * 删除
	 *
	 * @param id 主键
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("generate:project:delete")
	@DeleteMapping("/{id}")
	public R<?> deleteById(@PathVariable Long id) {
		generateProjectService.deleteById(id);
		return R.ok();
	}

	/**
	 * 修改
	 *
	 * @param id 主键
	 * @param generateProjectModifyDTO 更新dto
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("generate:project:modify")
	@PutMapping("/{id}")
	public R<?> modifyById(@PathVariable Long id,
	                       @RequestBody @Validated GenerateProjectModifyDTO generateProjectModifyDTO) {
		generateProjectService.modifyById(id, generateProjectModifyDTO);
		return R.ok();
	}

	/**
	 * 详情
	 *
	 * @param id 主键
	 * @return {@link R }<{@link GenerateProjectDetailVO }>
	 */
	@SaCheckPermission("generate:project:detail")
	@GetMapping("/detail/{id}")
	public R<GenerateProjectDetailVO> detailById(@PathVariable Long id) {
		GenerateProjectDetailVO generateProjectDetailVO = generateProjectService.detailById(id);
		return R.ok(generateProjectDetailVO);
	}

	/**
	 * 分页查询
	 *
	 * @param generateProjectPageDTO 分页查询条件
	 * @return {@link R }<{@link PageVO<GenerateProjectPageVO> }>
	 */
	@SaCheckPermission("generate:project:list")
	@GetMapping("/page")
	public R<PageVO<GenerateProjectPageVO>> queryPage(GenerateProjectPageDTO generateProjectPageDTO) {
		PageVO<GenerateProjectPageVO> page = generateProjectService.queryPage(generateProjectPageDTO);
		return R.ok(page);
	}
}
